package com.woniuxy.mallweb.controller;

import com.woniuxy.common.dto.SkuDto;
import com.woniuxy.mallweb.feign.OrderFeign;
import com.woniuxy.mallweb.feign.ProductFeign;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;

@Controller
public class MallController {

    @Autowired
    private ProductFeign productFeign;

    @Autowired
    private OrderFeign orderFeign;
    /**
     * 首页
     * 跳转页面
     * @return
     */
    @RequestMapping("/")
    public String index(){
        return "index";
    }

    @ResponseBody
    @GetMapping("/skuList")
    List<SkuDto> skuList(){
        return productFeign.skuList();
    }

    /**
     * 立即购买
     * @param skuId
     * @return
     */
    @PostMapping("/addOrder")
    @ResponseBody
    public String addOrder(Integer skuId){
        return orderFeign.addOrder(skuId);
    }

}
